package cn.tedu.api;

import java.util.Objects;

public class Test2_Object2 {
    public static void main(String[] args) {
        Student s1 = new Student("lsp",18);//触发了含参构造
        Student s2 = new Student("lsp",18);//触发了含参构造
        System.out.println(s1.hashCode());
        System.out.println(s1.toString());
        System.out.println(s1.equals(s1));
        System.out.println(s1.getAge());
        System.out.println(s1.getName());
        System.out.println(s1); //通过重写tostring直接打印属性
        System.out.println(s1.equals(s2));
    }
}
class Student{ //省略了 extends Object
    public Student(String name) {
        this.name = name;
    }

    public Student(int age) {
        this.age = age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }



    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;  //限制参与比较的数据类型
        return age == student.age &&
                Objects.equals(name, student.name);
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}